<template>
	<uni-easyinput :inputBorder="true" class="w-form-input" v-if="!readonly" v-model="_value"
		:prefixIcon="formProps.enableScan ? 'scan':null" @iconClick="scanCode"
		:placeholder="formProps.placeholder ? $t(formProps.placeholder) : $t('webAuto.enterContent')" />
	<view class="w-form-input-rv" v-else>
      <text style="line-height:70rpx">{{_value}}</text>
	</view>
</template>

<script setup>
	import { computed } from 'vue'
	import { useI18n } from 'vue-i18n';
	const { t } = useI18n();

	const props = defineProps({
		formProps: {
			type: Object,
			default: () => {
				return {}
			}
		},
		modelValue: String,
		readonly: Boolean
	})

	const _value = computed({
		get() {
			return props.modelValue
		},
		set(val) {
			emits('update:modelValue', val)
		}
	})

	const emits = defineEmits(['update:modelValue'])

	function scanCode() {
		uni.scanCode({
			success: (res) => {
				console.log(res.result)
				_value.value = res.result
			},
			fail: (err) => {
				console.log(err)
				uni.showToast({
					icon: 'none',
					title: t('webAuto.ScanException')
				})
			}
		})
	}
</script>

<style>
</style>